package com.easyhouse.controller;

import com.easyhouse.common.pojo.Cart;
import com.easyhouse.common.pojo.Product;
import com.easyhouse.common.vo.SysResult;
import com.easyhouse.service.CartService;
import com.easyhouse.user.UserApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cart/manage")
public class CartController {

    @Autowired
    private CartService cartService;

    @RequestMapping("/query")
    public List<Product> query(String userId){
        List<Product> products = cartService.queryProductsByUserId(userId);
        return products;
    }

    @RequestMapping("/save")
    public SysResult save(String userId, String productId){
        try {
            cartService.buyPrduct(userId,productId);
            return SysResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return SysResult.build(201,"购买失败",null);
        }
    }
}
